//
//  ThirdDetailTableViewCell.m
//  LANGirl
//
//  Created by 杨泓晔 on 16/3/8.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "ThirdDetailTableViewCell.h"

@interface ThirdDetailTableViewCell ()
@property (nonatomic,retain)UIImageView *myBackimageView;/**<背景白板*/
@property (nonatomic,retain)UILabel *myTextView;/**<内容*/
@property (nonatomic,retain)UIView *buttonView;
@end

@implementation ThirdDetailTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView{
    self.backgroundColor = LV;
    
    
    
    self.myBackimageView = [UIImageView new];
    [self.contentView addSubview:self.myBackimageView];
    self.myBackimageView.backgroundColor = [UIColor whiteColor];
    //裁掉边框
    self.myBackimageView.layer.masksToBounds = YES;
    //设置半径
    self.myBackimageView.layer.cornerRadius = 6 *AUTO_HEIGHT;
    [self.myBackimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(5);
        make.left.mas_equalTo(self.contentView.mas_left).offset(14);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-5);
        make.width.mas_equalTo(SCREEN_WIDTH - 14 * 2);
    }];
    self.myBackimageView.layer.borderWidth=1.0;
    self.myBackimageView.layer.borderColor=[[UIColor colorWithRed:0.819 green:0.808 blue:0.789 alpha:0.530]CGColor];
    
    
    
    
    
    UILabel *renwuL = [UILabel new];
   // renwuL.backgroundColor = [UIColor redColor];
    [self.myBackimageView addSubview:renwuL];
    [renwuL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.myBackimageView.mas_top).offset(18 * AUTO_HEIGHT/2);
        make.left.mas_equalTo(self.myBackimageView.mas_left).offset(32 * AUTO_WIDTH/2);
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        make.width.mas_equalTo(100 * AUTO_WIDTH);
    }];
    renwuL.text = @"任务详情";
    renwuL.alpha = 0.7;
    
    renwuL.textColor = [UIColor blackColor];
    renwuL.font = [UIFont systemFontOfSize:17.00*WEIGHT];
    
    
    
//    
//    UIView *linV = [UIView new];
//    linV.backgroundColor = [UIColor blackColor];
//    [self.myBackimageView addSubview:linV];
//    [linV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.myBackimageView.mas_top).offset(79 * AUTO_HEIGHT/2);
//        make.left.mas_equalTo(self.myBackimageView);
//        make.width.mas_equalTo(self.myBackimageView);
//        make.height.mas_equalTo(1 * AUTO_HEIGHT);
//    }];
//    linV.alpha = 0.1;
    
    //第一条线
    
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(15 * AUTO_WIDTH, 60/2 * AUTO_HEIGHT, 390 * AUTO_WIDTH, 20)];
    [self addSubview:imageView1];
    imageView1.alpha = 0.2;
    
    UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线
    [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状
    
    
    CGFloat leng1[] = {3,1};
    CGContextRef lin = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(lin, [UIColor blueColor].CGColor);
    
    CGContextSetLineDash(lin, 0, leng1, 2);  //画虚线
    CGContextMoveToPoint(lin, 0.0, 20.0);    //开始画线
    CGContextAddLineToPoint(lin, 340.0 * AUTO_WIDTH, 20.0);
    CGContextStrokePath(lin);
    
    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();
    
    
    
    
    
//    self.myTextView = [[UILabel alloc]initWithFrame:CGRectMake(15.00*WEIGHT, _detail.frame.size.height + _detail.frame.origin.y  - 5.00*HEIGHT , _threeView.frame.size.width-30.00*WEIGHT, 14.00*HEIGHT*6)];
    self.myTextView = [UILabel new];
    
    self.myTextView.numberOfLines = 18;
    self.myTextView.highlighted= YES;
    [self.myTextView setNumberOfLines:0];
      _myTextView.backgroundColor = [UIColor whiteColor];
      self.myTextView.font = [UIFont fontWithName:ZIXING size:13.00*WEIGHT];
    self.myTextView.userInteractionEnabled = NO;
    ////        [self.myTextView sizeToFit];
    self.myTextView.alpha = 0.6;
    [self.myBackimageView addSubview:self.myTextView];
    [self.myTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(14 * AUTO_HEIGHT * 6);
        make.right.mas_equalTo(self.myBackimageView.mas_right).offset(-15 * AUTO_HEIGHT);
        make.top.mas_equalTo(imageView1.mas_bottom).offset(10 * AUTO_HEIGHT);
        make.left.mas_equalTo(imageView1.mas_left).offset(15 * AUTO_WIDTH);
        
    }];
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:@"对于广州果粉来说，没有什么比得过Apple Store的广州首店更让人翘首以待。广州日报记者昨日在现场,Tim Cook表示，自己最喜欢的是3D Touch，因为3D Touch将重新定义触控方式，为用户带来更方便，更直觉化的使用体验，而有记者询问新一代iPhone(iPhone 7)时，Tim Cook表示会有新的大创新，产品准备好的话，就会即时推出，不会延期"];
    //
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:6];
    paragraphStyle1.lineBreakMode = NSLineBreakByTruncatingTail;
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [attributedString1 length])];
    [self.myTextView setAttributedText:attributedString1];

    /*
    
     
     
    //内容赋值
    self.contentsLabel.text = self.aStudent.contents;
#pragma mark--计算内容高度第2步: 计算Label高度
    //    CGFloat height = [StudentCell heightForContent:self.aStudent.contents];
    CGFloat height = [[self class] heightForContent:self.aStudent.contents];
    //    self.contentsLabel.frame.size.height = height;
    CGRect tempframe = self.contentsLabel.frame;
    tempframe.size.height = height;
    self.contentsLabel.frame = tempframe;
    
     
     
     
     */
}



#pragma mark-- 计算内容高度第一步
+ (CGFloat)heightForContent:(NSString *)content
{
    //参数1.设置计算高度按照什么样的size来计算
    //注意: 宽度一定与Label宽度一致，高度尽量大一点
    CGSize size = CGSizeMake(300, 10000);
    //参数2.设置计算类型
    //参数3.设置计算内容按照多大字体计算
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0], NSFontAttributeName, nil];
    //注意: 字体大小也要跟Label字体一样
    //参数4.系统备用参数，设置为nil
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
}

//cell适应文字高度大小
+(CGSize)labelRectWithSize:(CGSize)size
                 LabelText:(NSString *)labelText
                      Font:(UIFont *)font{
    NSDictionary  *dic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
    CGSize actualsize = [labelText boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return actualsize;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
